package com.hevery.security.core.validate.code.sms;

import com.hevery.security.core.validate.code.ValidateCode;
import com.hevery.security.core.validate.code.impl.AbstractValidateCodeProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.ServletRequest;

/**
 * @author: zhy
 * @description:
 * @date: created on 2017/11/6
 * @modified by:
 */
@Component("smsCodeProcessor")
public class SmsCodeProcessor extends AbstractValidateCodeProcessor<ValidateCode> {

    /**短信验证码发送器*/
    @Autowired
    private SmsCodeSender smsCodeSender;

    /**
     *  使用发送器将短信验证码发送出去
     * @param request
     * @param smsCode
     * @throws Exception
     */
    @Override
    protected void send(ServletWebRequest request, ValidateCode smsCode) throws Exception {

        String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), "mobile");
        smsCodeSender.send(mobile, smsCode.getCode());
    }
}
